package org.mybatis.generator.codegen.mybatis3;

import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.config.Context;

import java.sql.Types;

/*********************************************************
 * 文件名称：ExtMyBatis3FormattingUtilities.java
 * 系统名称：cxycloud
 * 模块名称：org.mybatis.generator.codegen.mybatis3
 * 功能说明：
 * 开发人员 @author：caoxy
 * 开发时间 @date：2023/8/24 15:56
 * 修改记录：程序版本  修改日期  修改人员  修改单号  修改说明
 *********************************************************/
public class ExtMyBatis3FormattingUtilities {
    public static final String ATTR_SELECT_BY_EXAMPLE_WITH_PAGE_STATEMENT_ID = "selectByExampleWithPage";
    public static final String ATTR_INSERT_BATCH_STATEMENT_ID = "insertBatch";
    public static final String ATTR_INSERT_COLUMN_LIST_ID = "Insert_Column_List";

    private static  boolean ENABLE_CRE_DATE_AND_UPD_DATE = false;


    public static void init(Context context){
        String enableCreAndUptDateToSysdate = context.getProperty("enableCreAndUpdDateToSysdate");
        if (enableCreAndUptDateToSysdate !=null && "true".equals(enableCreAndUptDateToSysdate)){
            ENABLE_CRE_DATE_AND_UPD_DATE = true;
        }
    }

    public static boolean insertSysdate(IntrospectedColumn introspectedColumn) {
        return ENABLE_CRE_DATE_AND_UPD_DATE &&
                ("CRE_DATE".equalsIgnoreCase(introspectedColumn.getActualColumnName()) ||
                        "UPD_DATE".equalsIgnoreCase(introspectedColumn.getActualColumnName())) &&
                Types.TIMESTAMP == introspectedColumn.getJdbcType();
    }

    public static boolean createSysdate(IntrospectedColumn introspectedColumn) {
        return ENABLE_CRE_DATE_AND_UPD_DATE &&
                "CRE_DATE".equalsIgnoreCase(introspectedColumn.getActualColumnName()) &&
                Types.TIMESTAMP == introspectedColumn.getJdbcType();
    }

    public static boolean updateSysdate(IntrospectedColumn introspectedColumn) {
        return ENABLE_CRE_DATE_AND_UPD_DATE &&
                "UPD_DATE".equalsIgnoreCase(introspectedColumn.getActualColumnName()) &&
                Types.TIMESTAMP == introspectedColumn.getJdbcType();
    }

    public static boolean tableAndColumnToLowerCase(Context context){
        String tableAndColumnToLowerCase = context.getProperty("tableAndColumnToLowerCase");
        if (tableAndColumnToLowerCase !=null && "true".equals(tableAndColumnToLowerCase)){
            return true;
        }else{
            return false;
        }
    }
}
